<template>
    <div>
    <el-form inline class="demo-form-inline">
    <el-row >
        <el-col :span="5">
            <el-form-item label="活动标题">
                <el-input v-model="query.payload.title" placeholder="活动标题" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="开始日期">
                <el-input v-model="query.payload.startTime" placeholder="开始日期" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="结束日期">
                <el-input v-model="query.payload.endTime" placeholder="结束日期" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="创建人">
                <el-input v-model="query.payload.userId" placeholder="创建人" />
            </el-form-item>
        </el-col>
    </el-row>
    <el-row >
        <el-form-item label="创建时间">
            <el-date-picker
                    v-model="query.dateRange"
                    type="datetimerange"
                    range-separator="到"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
            />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" activity @click="querySmsSeckillPromotion">查询</el-button>
            <el-button type="warning" activity @click="reset">重置</el-button>
            <el-button type="success" @click="addSmsSeckillPromotion">新增</el-button>
        </el-form-item>
    </el-row>
    </el-form>
    <el-divider style="margin: 12px 0"/>
    <el-table ref="table" border v-loading="loading"  :data="data.tableData" header-cell-class-name="headerClass">
        <el-table-column align="center" type="index"  label="序号" width="100px" />
        <el-table-column align="center" prop="title" label="活动标题" />
        <el-table-column align="center" prop="startTime" label="开始日期" />
        <el-table-column align="center" prop="endTime" label="结束日期" />
        <el-table-column align="center" prop="status" label="上下线状态" />
        <el-table-column align="center" prop="userId" label="创建人" />
        <el-table-column align="center" prop="updateTime" label="更新时间" >
            <template #default="scope">
                {{moment(scope.row.updateTime).format("yyyy-MM-DD HH:mm:ss")}}
            </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
            <template #default="scope">
                <el-link title="修改" type="primary" @click="editSmsSeckillPromotion(scope.row.id)">
                    <el-icon :size="20">
                        <Edit />
                    </el-icon>
                    修改
                </el-link>
                &nbsp;
                <el-popconfirm title="删除？" @confirm="deleteSmsSeckillPromotion(scope.row.id)"  @cancel="">
                    <template #reference>
                        <el-link type="danger" title="删除">
                            <el-icon :size="20">
                                <Delete />
                            </el-icon>
                            删除
                        </el-link>
                    </template>
                </el-popconfirm>
            </template>
        </el-table-column>
</el-table>
<el-pagination
        style="display: flex;align-items:center;justify-content:center;"
        v-model:currentPage="query.currentPage"
        v-model:page-size="query.pageSize"
        :page-sizes="[10, 20, 30]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
        @size-change="querySmsSeckillPromotion"
        @current-change="querySmsSeckillPromotion"
/>
<ModSmsSeckillPromotion @close="modSmsSeckillPromotion.isOpen = false"  @reload="querySmsSeckillPromotion"
              ref="modSmsSeckillPromotion"
              :openType="transData.openType"
              :id="transData.id" />
</div>
</template>

<script setup>
    import ModSmsSeckillPromotion from '@/views/mall/sms/components/ModSmsSeckillPromotion.vue'
    import request from '@/utils/request.js'
    import { ElMessage } from 'element-plus'
    import {ref, reactive, onMounted} from 'vue'
    import moment from 'moment'
    let transData = reactive({})
    let modSmsSeckillPromotion = ref(null)
    let data = reactive({
        modRole:false,
        tableData:[],
        openType:"",
        id:"",
    });
    let loading = ref(true)
    let query = reactive({dateRange:[],payload:{}, currentPage:1,pageSize:10,total:0})
    onMounted(() => {
        querySmsSeckillPromotion()
    })
    function querySmsSeckillPromotion(){
        query.startTime = query.dateRange[0]
        query.endTime = query.dateRange[1]
        request.post("/api/smsSeckillPromotion/getSmsSeckillPromotionPage", query).then(resp => {
            data.tableData = resp.records
            query.total = resp.total
            loading.value = false
        })
    }

    function reset(){
        query.payload.title = ""
        query.payload.startTime = ""
        query.payload.endTime = ""
        query.payload.status = ""
        query.payload.userId = ""
        query.dateRange=[]
    }

    function addSmsSeckillPromotion(){
        transData.openType = "add"
        modSmsSeckillPromotion.value.isOpen = true
    }

    function deleteSmsSeckillPromotion(id){
        request.get(`/api/smsSeckillPromotion/delete/${id}`).then(resp => {
            querySmsSeckillPromotion()
            ElMessage({message: '删除成功！',openType: 'success'})
        });
    }

    function editSmsSeckillPromotion(id){
        transData.id = id
        transData.openType = "edit"
        modSmsSeckillPromotion.value.isOpen = true
    }

</script>
<style lang="css">

</style>


